package com.wisezone.permission.web;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import com.wisezone.common.annotation.WzWebAnnotation;
import com.wisezone.common.exception.WzWebException;
import com.wisezone.common.utils.BeanUtils;
import com.wisezone.common.web.BaseFormController;
import com.wisezone.permission.bean.entity.WzRescEntity;
import com.wisezone.permission.bean.form.WzMenuForm;
import com.wisezone.permission.bean.form.WzRescForm;
import com.wisezone.permission.bean.search.WzRescSearch;
import com.wisezone.permission.service.WzRescService;

/**
 * 
 *资源; InnoDB free: 24576 kB
 * 
 * @author create by create date 2010-07-29 14:44:45 update date 2010-07-29
 *         14:44:45
 * 
 */
@WzWebAnnotation(moduleName = "resc")
public class WzRescController extends
		BaseFormController<WzRescEntity, WzRescSearch, WzRescForm> {

	/**
	  *
	  *
	  *
	  */
	private WzRescService wzRescService;

	private List<WzRescEntity> parentList = null;

	private final String TREE = "tree";

	/**
	 * 返回清空条件列表
	 * 
	 * @return
	 * @throws WzWebException
	 */
	public String toList() throws WzWebException {

		return LIST;
	}

	/**
	 * 获得列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() throws WzWebException {

		return LIST;
	}

	/**
	 * 进入新增
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterNew() throws WzWebException {

		if (id != null) {
			entity = new WzRescEntity();
			entity.setParentId(id);
		}
		return NEW_EDIT;
	}

	/**
	 * 进入修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterEdit() throws WzWebException {

		entity = this.wzRescService.findById(id);
		return NEW_EDIT;
	}

	/**
	 * 进入树列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterTree() throws WzWebException {

		// 获得菜单列表
		searchEntity = getSearchEntity();
		List<WzRescForm> rescList = wzRescService.getRescList(searchEntity
				.getName());
		model.put("rescList", rescList);
		return TREE;
	}
	

	/**
	 * 保存
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws WzWebException {

		if (id != null) {
			return update();
		}
		entity = getEntity();
		this.wzRescService.save(entity);
		return toList();
	}

	/**
	 * 修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String update() throws WzWebException {

		entity = getEntity();
		WzRescEntity oldEntity = this.wzRescService.findById(id);
		BeanUtils.copyBean(oldEntity, entity);
		this.wzRescService.update(oldEntity);
		return toList();
	}

	/**
	 * 删除
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws WzWebException {

		Collection<Serializable> idList = getIdList();
		if (idList != null) {
			this.wzRescService.deleteAll(idList);
		}
		return toList();
	}

	public List<WzRescEntity> getParentList() {

		parentList = this.wzRescService.getParentList();
		return parentList;
	}

	public void setWzRescService(WzRescService wzRescService) {
		this.wzRescService = wzRescService;
	}

}